package indigo.collections 
{
	/**
	 * A typical Queue implementation. You can add items to the Queue, peek in the first element without deleting it,
	 * and poll the first element, which will delete it from the Queue.
	 * @author Sebastiaan Holtrop
	 */	
	public class Queue 
	{
		internal var _queue:LinkedList;
		
		/**
		 * Constructor. 
		 */		
		public function Queue():void
		{
			_queue = new LinkedList();
		}
		
		
		/**
		 * Function to detect if the Queue is empty. 
		 * @return Boolean Returns true if the Queue is empty, otherwise returns false.
		 */		
		public function isEmpty():Boolean
		{
			return _queue.isEmpty()
		}
		
		
		/**
		 * Adds an item to the Queue. 
		 * @param item
		 */		
		public function add(item:*):void
		{
			_queue.prepend(item);
		}
		
		
		/**
		 * Removes the first item from the Queue and returns it. 
		 * @return * Returns the first item from the Queue.
		 */		
		public function poll():*
		{
			return _queue.shift();
		}
		
		
		/**
		 * Returns the first item in the Queue without removing it. 
		 * @return * The first item from the Queue. 
		 */		
		public function peek():*
		{
			return _queue.firstLinkedListItem.data;
		}
		
		
		/**
		 * Returns the number of items currently in the Queue. 
		 * @return int
		 */
		public function size():int
		{
			return _queue.size;
		}
		
		
		/**
		 * Returns a string representation of the elements in the Queue.
		 * @return String
		 */
		public function toString():String
		{
			return _queue.toString();
		}
	}
}